import axios from "axios";
// import { message } from 'antd'
import { getStorage, setStorage } from './utils'
let http = axios.create({
  baseURL: "/api",
  timeout: 60000,
});

http.interceptors.request.use((res) => {
  let token = getStorage('token')
  // let token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiMTc3MTEyODcxMDQiLCJpYXQiOjE2MDg4MDc0NTIsImV4cCI6MTYwODg2NzQ1Mn0.3_PjquuNwFQQWkCEtmP8ThjvBwdWBxXGIR7cePw0IQw"
  token && (res.headers['Authorization'] = token)
  // token && (res.headers['Authorization'] = `Bearer ${token}`)
  console.log(res.headers);
  /* 这里配置请求参数,例如token等公用参数 */
  return res;
});
http.interceptors.response.use((resp) => {
  /* 这里配置响应参数,例如统一配置请求参数错误情况及存储token */
  resp.data.token && setStorage('token', resp.data.token)
  return resp;
},error => {
  console.log(error)

    // let _resp = error.response
    // if (_resp.status === 500) {
    //   message.error('服务器开小差了')
    // } else if (_resp.status === 404) {
    //   message.error('服务器被干掉了')
    // }

    // return Promise.reject(error.response.data)
  });

export default http;